using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Preferences;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Xamarin.ActionbarSherlockBinding.Views;
using Xamarin.ActionbarSherlockBinding.App;
using IMenuItem = Xamarin.ActionbarSherlockBinding.Views.IMenuItem;

namespace jivemessenger
{
    [Activity(Label = "Preferences")]
    public class PrefActivity : SherlockPreferenceActivity, ISharedPreferencesOnSharedPreferenceChangeListener
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            AddPreferencesFromResource(Resource.Xml.Preferences);
            SupportActionBar.SetDisplayShowHomeEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            SupportActionBar.NavigationMode = Xamarin.ActionbarSherlockBinding.App.ActionBar.DisplayHomeAsUp;
            SupportActionBar.SetDisplayShowTitleEnabled(true);

        }

        protected override void OnResume()
        {
            base.OnResume();
            PreferenceManager.GetDefaultSharedPreferences(this).RegisterOnSharedPreferenceChangeListener(this);
        }

        protected override void OnPause()
        {
            base.OnPause();
            PreferenceScreen.SharedPreferences.
                UnregisterOnSharedPreferenceChangeListener(this);
        }

        public void OnSharedPreferenceChanged(ISharedPreferences sharedPreferences, string key)
        {
            Preference pref = FindPreference(key);

            if (pref is ListPreference)
            {
                ListPreference listPref = (ListPreference)pref;
                listPref.Summary = listPref.Entry;
            }
        }
        public override bool OnMenuItemSelected(int featureId, IMenuItem item)
        {
            switch (item.ItemId)
            {
                case Android.Resource.Id.Home:
                    Finish(); //?
                    break;
            }
            return true;
        }
    }
}